/**
 * 用于常规判断变量的合法性
 */
(function(window, undefined){

    var classtype = {};
    classtype["[object Boolean]"] = "Boolean".toLowerCase();
    classtype["[object Number]"] = "Number".toLowerCase();
    classtype["[object String]"] = "String".toLowerCase();
    classtype["[object Function]"] = "Function".toLowerCase();
    classtype["[object Array]"] = "Array".toLowerCase();
    classtype["[object Date]"] = "Date".toLowerCase();
    classtype["[object RegExp]"] = "RegExp".toLowerCase();
    classtype["[object Object]"] = "Object".toLowerCase();

    var Tools = (function(){
        var tools = function () {};

        tools.prototype = {
            _type : function (obj) {
                return obj == null ?
                    String(obj) : classtype[Object.prototype.toString.call(obj)] || "object";
            },
            isFunction: function (obj) {
                return this._type(obj) === "function";
            },

            isString: function (obj) {
                return this._type(obj) === "string";
            },

            isArray : function(obj){
                return this._type(obj) === "array";
            },

            isObject: function (obj) {
                return this._type(obj) === "object";
            },

            hasJQuery: function () {
                return !(undefined == window.jQuery || undefined == window.$ || undefined == jQuery);
            },
            isNum: function (num) {
                if (num != null) {
                    var r, re;
                    re = /\d+/i;
                    r = num.match(re);
                    return (r == num) ? true : false;
                }
                return false;
            },
            isNull: function (obj) {
                return (obj == undefined || obj == null || obj === "" || this.isObjNull(obj) || obj.length == 0);
            },
            isEmpty : function(obj){
                if(this.isObjNull(obj) || '' === obj || 0 == obj.length )
                    return true;
                return false;
            },
            isObjNull : function (obj) {
                for (var key in obj){
                    return false;//返回false，不为空对象
                }
                return true;//返回true，为空对象
            },
            isNulls: function () {
                var input = arguments;
                for (var i = 0; i < input.length; i++) {
                    if (this.isNull(input[i]))
                        return true;
                }
                return false;
            },
            uuid : function(len, radix) {
                var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
                var uuid = [], i;
                radix = radix || chars.length;
                if (len) {
                    for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
                } else {
                    var r;
                    uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
                    uuid[14] = '4';
                    for (i = 0; i < 36; i++) {
                        if (!uuid[i]) {
                            r = 0 | Math.random()*16;
                            uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
                        }
                    }
                }

                return uuid.join('');
            }
        };
        return tools;
    })();

    window.staticTools = new Tools();

})(window);